//
//  WPSettingViewController.m
//  wobingwoyi
//
//  Created by WGP on 16/8/4.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPSettingViewController.h"
#import "APPDelegate.h"
#import "WPTabBarController.h"
#import "WPSoftwareAgreementVC.h"

@interface WPSettingViewController ()<UIAlertViewDelegate>

@end

@implementation WPSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}

- (IBAction)back:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)settingBtnDidClick:(UIButton *)sender
{
    if (sender.tag == 203)
    {
//        跳转到Appstore,https://itunes.apple.com/cn/app/qq/id444934666?mt=8
         [[UIApplication sharedApplication] openURL:kAppStoreURL];
    }
    else if (sender.tag == 202)
    {
        WPSoftwareAgreementVC *vc = [WPSoftwareAgreementVC new];
        vc.PageTitle = @"用户协议";
        vc.url = @"https://www.wobingwoyi.com:8443/wbwy/page/agreement.do";
        [self.navigationController pushViewController:vc animated:YES];
    }
}
- (IBAction)loginOut
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"友情提示" message:@"确定要退出当前登录么?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertView show];

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1)
    {
//        用户退出登录的时候取消极光别名
        [JPUSHService setAlias:@"" callbackSelector:nil object:self];
        
//        调用退出登录的借口
        NSString *url = @"user/logout.do";
        [[WPNetWorkManager sharedNetWorkManager] POST:url parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        }];
        
        NSFileManager *defaultManager = [NSFileManager defaultManager];
        if([defaultManager removeItemAtPath:filepath error:NULL])
        {
//            WPLog(@"删除归档文件成功");
        }
        [defaultManager removeItemAtPath:MRFilePath error:NULL];
        
        [WPUserAccountViewModel sharedInstance].userAccount = nil;
        
        //取消第三方登录授权
        [ShareSDK cancelAuthorize:SSDKPlatformTypeWechat];
        [ShareSDK cancelAuthorize:SSDKPlatformTypeSinaWeibo];
        [ShareSDK cancelAuthorize:SSDKPlatformTypeQQ];
        
        //友盟账号登出时需调用此接口，调用之后不再发送账号相关内容
        [MobClick profileSignOff];
        
        [(AppDelegate *)([UIApplication sharedApplication].delegate) switchController:[WPTabBarController new]];
    }
}

@end
